<template>
	<view class="big">
		<view class="herder">
			<image :src="userimg"></image>
			<view v-text="username"></view>
			<!-- 按钮触发授权申请 -->
			<!-- #ifdef MP-WEIXIN -->
			<button open-type="getUserInfo" @getuserinfo="wxGetUserInfo" withCredentials="true" class="powerBtn" v-show="userbtn">登录</button>
			<!-- #endif -->
		</view>
		<view class="top2">
			<view>0.00元<br /><span>余额</span></view>
			<view class="youhui">4个<br /><span>优惠</span></view>
			<view>58222分<br /><span>积分</span></view>
		</view>


		<view class="middel">
			<uni-list class="list">
				<view class="item" v-for="(item,index) in list" :key=index>
					<view class="iconfont" :class="item.icon"></view>
					<uni-list-item thumb=" " class="listItem" @click="jump(index)" :title="item.title">
					</uni-list-item>
				</view>
			</uni-list>
		</view>

	</view>
</template>

<script>
	import {
		uniIcon,
		uniList,
		uniListItem
	} from "@dcloudio/uni-ui";
	import '../../static/iconfont/iconfont.css';
	var list = [{
			'title': '我的收藏',
			'icon': ' iconshoucang'
		},
		{
			'title': '推荐有奖',
			'icon': ' icon21'
		},
		{
			'title': '积分商城',
			'icon': ' iconshouye'
		},
		{
			'title': '店家会员卡',
			'icon': ' iconhuiyuanqia'
		},
		{
			'title': '服务中心',
			'icon': ' iconfuwu'
		},
		{
			'title': '欢迎评分',
			'icon': ' icondianzan'
		},
	]
	export default {
		data() {
			return {
				userimg:getApp().globalData.userimg,
				username:getApp().globalData.username,
				opid:getApp().globalData.opid,
				userbtn:true,
				list: list,
			};
		},
		onLoad() {
			this.isuserlogin();
			},
		methods: {
			//点击授权按钮
			wxGetUserInfo(res){
				//未授权
				if (!res.detail.iv) {
					// uni.showToast({
					// 	title: "取消授权",
					// });
				}else{
					//已授权
					this.userbtn=false;
					getApp().$vm.getUserInfo();
					setTimeout(()=>{this.isuserlogin()},1500)
				}
				},
			//用户是否登录
			isuserlogin(){
				//未授权
				if(getApp().globalData.userimg==''){
					this.userimg='/static/icon/weixin.png';
					this.username='登录';
				}else{
					//已授权
					console.log('已授权');
					console.log(this.userimg)
					this.userbtn=false;
					this.userimg=getApp().globalData.userimg;
					this.username=getApp().globalData.username;
				}
			},
			//列表跳转
			jump: function(index) {
				if (index == 0) {
					uni.navigateTo({
						url: 'my-collect?id=1&name=uniapp'
					});
				}
			},
			
		},
		components: {
			uniIcon,
			uniList,
			uniListItem,
		}
	}
</script>


<style lang="less">
	//引入外部less文件
	@import url("my.less");
	.powerBtn {
		outline: none;
		background-color: transparent;
		width: 100%;
		z-index: 99;
		font-size:19px;
		position:absolute;
		top: 0;
		left: 0;
		padding: 90px 0;
		font-size:0;
		&::after{
			border: 0;
		}
	}
</style>
